Skip to content

refactor: #718 only drop TimestampSeries #1274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

cmp0xff
Copy link
Contributor

@cmp0xff cmp0xff commented Jul 13, 2025

@cmp0xff cmp0xff marked this pull request as ready for review July 13, 2025 07:05
@cmp0xff cmp0xff changed the title fix: #718 only drop TimestampSeries refactor: #718 only drop TimestampSeries Jul 13, 2025
@cmp0xff cmp0xff force-pushed the hotfix/cmp0xff/gh718-drop-tss branch from c81cd6e to d5e1089 Compare July 16, 2025 17:54
@cmp0xff cmp0xff marked this pull request as draft July 16, 2025 17:56
@cmp0xff cmp0xff force-pushed the hotfix/cmp0xff/gh718-drop-tss branch from d5e1089 to 41c7015 Compare July 16, 2025 18:19
@cmp0xff cmp0xff marked this pull request as ready for review July 16, 2025 20:11
@cmp0xff cmp0xff force-pushed the hotfix/cmp0xff/gh718-drop-tss branch 2 times, most recently from abf9147 to cbbd372 Compare July 17, 2025 15:10
@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Jul 23, 2025

@cmp0xff you have a number of PRs submitted while I was out on vacation for 2 weeks. Can you let me know which ones I should prioritize for review?

@cmp0xff
Copy link
Contributor Author

cmp0xff commented Jul 23, 2025

Hi @Dr-Irv, I hope you had a nice vacation. My pull requests are categorised below. Each category is independent, but those in a higher position have a slightly higher priority in my opinion.

Series: arithmetic operations

The following two PRs are independent. They migrate test_series.py to a subfolder series, and add quite a few test_*.py files there.

DataFrame.to_dict

Index.append

Series: address #718

  1. refactor: #718 only drop TimestampSeries #1274 - this is a prerequisite for the next one.
  2. refactor: #718 also drop TimedeltaSeries #1273

Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this. It's a lot of good work.

Main thing - if I'm going to merge this PR, it needs to be in a state where we don't need the followup PR.

Basic rule - we don't put ignore in the tests unless we are testing that the stubs should not accept something that is invalid. You have places where you have added ignore in the tests and I won't merge that in (unless we know it is a bug in the type checker)

Comment on lines 2819 to 2821
check(assert_type(s + summer, pd.Series), pd.Series) # type: ignore[assert-type]
check(assert_type(s + df["y"], pd.Series), pd.Series) # type: ignore[assert-type]
check(assert_type(summer + summer, pd.Series), pd.Series) # type: ignore[assert-type]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't want to have ignore in the tests. Fix the types to make this work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not there anymore.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Jul 24, 2025

Hi @Dr-Irv, I hope you had a nice vacation. My pull requests are categorised below. Each category is independent, but those in a higher position have a slightly higher priority in my opinion.

I've reviewed them all, except #1273 as noted there.

Thanks for all the great work.

@cmp0xff
Copy link
Contributor Author

cmp0xff commented Jul 24, 2025

I've reviewed them all, except #1273 as noted there.

Thanks for all the great work.

Thank you very much for your quick and thorough reviews. I will be able to work on them next week.

@cmp0xff cmp0xff force-pushed the hotfix/cmp0xff/gh718-drop-tss branch from cbbd372 to ed69ec5 Compare July 28, 2025 15:05
@cmp0xff cmp0xff marked this pull request as draft July 30, 2025 07:52
@cmp0xff cmp0xff force-pushed the hotfix/cmp0xff/gh718-drop-tss branch from b095af2 to f1cf19f Compare August 4, 2025 21:36
@cmp0xff cmp0xff force-pushed the hotfix/cmp0xff/gh718-drop-tss branch from 3202bda to c4d657e Compare August 6, 2025 07:24
@cmp0xff
Copy link
Contributor Author

cmp0xff commented Aug 6, 2025

Hi @Dr-Irv @twoertwein, it is difficult to remove only TimestampSeries. If we do so, for example, Series[Timestamp] - Series[Timestamp] would give TimedeltaSeries. Having this, mypy and pyright have different opinions handling Series[Any] - Series[Any]. mypy gives Any, whereas pyright gives Series[Any].

Can we go back to the original plan, and remove both TimestampSeries and TimedeltaSeries in one PR?

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Aug 6, 2025

Hi @Dr-Irv @twoertwein, it is difficult to remove only TimestampSeries. If we do so, for example, Series[Timestamp] - Series[Timestamp] would give TimedeltaSeries. Having this, mypy and pyright have different opinions handling Series[Any] - Series[Any]. mypy gives Any, whereas pyright gives Series[Any].

Can we go back to the original plan, and remove both TimestampSeries and TimedeltaSeries in one PR?

OK, you can try. But I think this may be something you can't fix due to how mypy is handling things, and that's why I had to create TimestampSeries and TimedeltaSeries in the first place.

@cmp0xff
Copy link
Contributor Author

cmp0xff commented Aug 7, 2025

Hi @Dr-Irv, I continued working on the current #1274 anyway. Please let me know if you think we can proceed to merge it, or if we need to do better. In the latter case, I believe I have to remove both TimestampSeries and TimedeltaSeries together.

Summary

Highlights

  • TimestampSeries removed
  • All except 1 existing tests pass
  • All review comments replied to

To-dos

  • 1 test fails, inline commented with reasons, expected to be fixed when removing TimedeltaSeries
  • Series[Timedelta] is used at several places, expected to be fixed when removing TimedeltaSeries
  • Overloads of Series.__mul__ is suboptimal, can be fixed in a separate PR

Orphaned comments

#1274 (comment)

need to not be there now

code removed, see #1274 (comment)

#1274 (comment)

but you shouldn't have the ignores here. I'm really hesitant to accept this change in this PR without knowing that both PRs work together without this change.

explained in #1274 (comment)

#1274 (comment)

I don't understand this comment.

code removed, see #1274 (comment)

@cmp0xff cmp0xff marked this pull request as ready for review August 7, 2025 15:48
@cmp0xff cmp0xff requested a review from Dr-Irv August 7, 2025 15:51
Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty close. There are 2 main issues reflected in the comments.

  1. I think the changes you made for __sub__() and possibly __mul__() and related methods to handle int, float, etc., should be a separate PR, similar to what you did for _add__() and __div__(). If we can get that working, and then do this one, it will be easier to make sure all the tests are still working right.
  2. I don't want to merge with any new ignore in the tests, because if someone pulls main, they will get something we know is broken. But I suggest a plan for handling that in the comments.

Thanks again for the great work on this.

Comment on lines +2791 to +2793
check(x.astype(cast_arg), pd.Series, target_type)
else:
check(s.astype(cast_arg), TimestampSeries, target_type)
check(s.astype(cast_arg), pd.Series, target_type)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these both be pd.Series[pd.Timestamp] ?

Comment on lines +1604 to +1605
# Will be fixed after removing TimedeltaSeries, see Series.__sub__ in series.pyi
check(assert_type(ss, pd.Series), pd.Series) # type: ignore[assert-type]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm don't want to merge until we deal with this, because everything in main should pass all the tests. But here is what I'd like to do. Once I'm OK with this PR, I won't merge it, and then the TimedeltaSeries PR can merge into this branch where the line above should get fixed.

I could put this branch into the repo once approved so it becomes the new PR target of the next PR, and then once that is approved and merged, we do a new PR from that branch to main

# is invoked, but because of how Series.dt is hooked in and that we may not know the
# type of the series, we don't know which kind of series was ...ed
# in to the dt accessor

_DTTimestampTimedeltaReturnType = TypeVar(
"_DTTimestampTimedeltaReturnType",
bound=Series | TimestampSeries | TimedeltaSeries | DatetimeIndex | TimedeltaIndex,
"_DTTimestampTimedeltaReturnType", bound=Series | DatetimeIndex | TimedeltaIndex
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not clear why TimedeltaSeries is removed at this point. Or shouldn't it be bound=Series | Series[Timestamp] | TimedeltaSeries | DatetimeIndex | TimedeltaIndex ?

I know that Series includes the other 2, but I'd like to keep this as close as possible to what was there before.

Comment on lines +2018 to +2040
@overload
def __sub__(self: Series[S1C], other: Series[Never]) -> Series: ...
@overload
def __sub__(
self: Series[Timestamp],
other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64,
) -> TimestampSeries: ...
self: Series[int], other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX]
) -> Series[_T_COMPLEX]: ...
@overload
def __sub__(self: Series[int], other: np_ndarray_anyint) -> Series[int]: ...
@overload
def __sub__(self: Series[int], other: np_ndarray_float) -> Series[float]: ...
@overload
def __sub__(self: Series[int], other: np_ndarray_complex) -> Series[complex]: ...
@overload
def __sub__(
self: Series[Timedelta],
other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64,
) -> TimedeltaSeries: ...
self: Series[float],
other: int | Sequence[int] | np_ndarray_anyint | np_ndarray_float | Series[int],
) -> Series[float]: ...
@overload
def __sub__(
self: Series[float],
other: _T_COMPLEX | Sequence[_T_COMPLEX] | Series[_T_COMPLEX],
) -> Series[_T_COMPLEX]: ...
@overload
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these changes for __sub__() and __rsub__() and sub() should be in a separate PR like you did for add and div, with the tests like you did there.

@overload
def __rtruediv__( # pyright: ignore[reportIncompatibleMethodOverride]
self: Series[Timedelta], other: _nonseries_timedelta | Series[Timedelta]
) -> Series[float]: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can delete the first __rtruediv__() declaration (or combine the 2) because it is returning the same result, and self is already a subclass of Series[Timedelta] . Not 100% sure of that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants